//
//  THPopupBaseView.m
//  THCalendar
//
//  Created by 魏鑫 on 2021/1/4.
//

#import "THPopupBaseView.h"
#import "UIView+PKExtend.h"
#import "UIColor+String.h"
#import "UIControl+PKExtend.h"

@interface THPopupBaseView ()

@property (nonatomic,strong,readwrite) UIView *contentView;
@property (nonatomic,strong,readwrite) UILabel *titleLabel;
@property (nonatomic,strong,readwrite) UIButton *closeButton;

@end

@implementation THPopupBaseView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupSubViews];
        [self setupUI];
        [self setupLayout];
    }
    return self;
}

- (void)setupSubViews
{
    [self addSubview:self.contentView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.closeButton];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.contentView.frame = self.bounds;
    
    CGSize titleSize = [self.titleLabel sizeThatFits:CGSizeMake(self.bounds.size.width, 50)];
    
    self.titleLabel.frame = CGRectMake((self.bounds.size.width-titleSize.width)/2., 0, titleSize.width, 50);
    
    self.closeButton.frame = CGRectMake(16, 16, 20, 20);
}

#pragma mark - pubilc

- (void)setupUI
{
    
}

- (void)setupLayout
{
    
}

#pragma mark - getter

- (UIView *)contentView
{
    if (!_contentView) {
        _contentView = [[UIView alloc] initWithFrame:self.bounds];
        _contentView.backgroundColor = [UIColor whiteColor];
        [_contentView pk_addCornerRadius:10 byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft];
    }
    return _contentView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor colorWithString:@"#333333"];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _titleLabel;
}

- (UIButton *)closeButton
{
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageNamed:@"back_close"] forState:UIControlStateNormal];
        _closeButton.pk_enlargeTouchInsets = UIEdgeInsetsMake(20, 20, 10, 20);
    }
    return _closeButton;
}

@end
